﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using System.Data;

namespace Core.Dao
{
    class BankDao
    {
        public bool insert(Bank bank)
        {
            object[,] param = {
                {"@Name", bank.Name},
                {"@Desc", bank.Desc},
            };
            String sql = "insert into BANKS(BNK_NAME, BNK_DESC) " +
                "values(@Name, @Desc)";
            return DB.exec(sql, param);
        }

        public bool update(Bank bank)
        {
            object[,] param = {
                {"@Name", bank.Name},
                {"@Desc", bank.Desc},
                {"@id", bank.Id},
            };
            String sql = "update BANKS set BNK_NAME = @Name, BNK_DESC = @Desc " +
                "where BNK_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "delete from BANKS where BNK_ID = @id";
            return DB.exec(sql, param);
        }

        public bool delete(String ids)
        {
            object[,] param = {
                {"@ids", ids}   
            };
            String sql = "delete from BANKS where BNK_ID in (" + ids + ")";
            return DB.exec(sql);
        }

        public DataTable get(int id)
        {
            object[,] param = {
                {"@id", id}   
            };
            String sql = "select * from BANKS where BNK_ID = @id";
            return DB.getData(sql, param);
        }

        public DataTable getAll()
        {
            String sql = "select * from BANKS order by BNK_NAME";
            return DB.getData(sql);
        }
    }
}
